<template>
  <div class="order-container">
    <!-- 顶部导航栏 -->
    <header class="top-nav">
      <div class="logo">订单管理系统</div>
      <button class="logout-btn" @click="handleLogout">
        <i class="fa fa-sign-out"></i> 退出登录
      </button>
    </header>

    <!-- 主内容区 -->
    <div class="main-content">
      <!-- 左侧导航区 -->
      <aside class="sidebar">
        <button 
          class="nav-btn" 
          @click="goToHome"
        >
          <i class="fa fa-home"></i> 首页
        </button>
        <button 
          class="nav-btn active" 
          @click="activeTab = 'orderManage'"
        >
          <i class="fa fa-list-alt"></i> 订单管理
        </button>
        
        <!-- 身份对应功能入口 -->
        <button 
          class="role-entry-btn"
          @click="goToRolePage"
          v-if="userDetail.identity"
        >
          <i :class="roleIcon"></i> 
          {{ rolePageName }}
        </button>
      </aside>

      <!-- 中间工作区域 -->
      <section class="work-area">
        <!-- 页面标题 -->
        <div class="page-title">
          <h2>{{ activeTab === 'orderManage' ? '订单处理' : '历史记录' }}</h2>
          <div class="identity-tag" v-if="userDetail.identity">
            {{ identityMap[userDetail.identity] }}身份
          </div>
        </div>

        <!-- 加载状态 -->
        <div v-if="isLoading" class="loading-state">
          <i class="fa fa-circle-o-notch fa-spin"></i>
          <p>加载数据中...</p>
        </div>

        <!-- 错误提示 -->
        <div v-if="!isLoading && errorMessage" class="error-state">
          <i class="fa fa-exclamation-circle"></i>
          <p>{{ errorMessage }}</p>
          <button 
            class="reload-btn" 
            @click="fetchData()"
            v-if="errorScene !== 'identity_incomplete'"
          >
            重新加载
          </button>
          <button 
            class="go-profile-btn" 
            @click="goToHomeProfile"
            v-if="errorScene === 'identity_incomplete'"
          >
            去完善身份信息
          </button>
        </div>

        <!-- 空状态 -->
        <div v-if="!isLoading && !errorMessage && currentOrders.length === 0" class="empty-state">
          <i class="fa fa-file-text-o"></i>
          <p>{{ activeTab === 'orderManage' ? '暂无待处理订单' : '暂无历史订单记录' }}</p>
          <p class="tip">
            {{ activeTab === 'orderManage' ? '有新订单会实时显示在这里' : '暂无已完成的订单' }}
          </p>
        </div>

        <!-- 订单列表 -->
        <div 
          class="order-list" 
          v-if="!isLoading && !errorMessage && currentOrders.length > 0"
        >
          <div 
            class="order-card" 
            v-for="order in currentOrders" 
            :key="order.id"
          >
            <!-- 订单头部信息 -->
            <div class="order-header">
              <div class="order-basic">
                <h3 class="order-number">订单编号：{{ order.order_id || `ORDER-${order.id}` }}</h3>
                <div class="order-meta">
                  <span class="order-time">
                    <i class="fa fa-clock-o"></i> {{ formatTime(order.create_time) }}
                  </span>
                  <span 
                    class="order-status"
                    :class="getStatusClass(order.status)"
                  >
                    {{ getStatusText(order.status) }}
                  </span>
                </div>
              </div>
            </div>

            <!-- 订单详情 -->
            <div class="order-detail">
              <!-- 收货信息 -->
              <div class="recipient-info" v-if="[1, 3].includes(userDetail.identity)">
                <h4 class="detail-title">收货信息</h4>
                <p><i class="fa fa-user"></i> {{ order.user_name || '匿名用户' }}</p>
                <p><i class="fa fa-phone"></i> {{ order.phone || '未填写手机号' }}</p>
                <p><i class="fa fa-map-marker"></i> {{ order.address || '未填写地址' }}</p>
              </div>

              <!-- 商品清单 -->
              <div class="commodity-list">
                <h4 class="detail-title">商品清单</h4>
                <div 
                  class="commodity-item" 
                  v-for="(item, index) in order.order_details" 
                  :key="index"
                >
                  <span class="commodity-name">{{ item.commodity_name || `商品${index + 1}` }}</span>
                  <span class="commodity-count">×{{ item.number }}</span>
                  <span class="commodity-price">¥{{ formatPrice(item.price) }}</span>
                </div>
              </div>

              <!-- 订单金额 -->
              <div class="order-amount">
                <span class="amount-label">订单总计：</span>
                <span class="amount-value">¥{{ formatPrice(order.sum) }}</span>
              </div>
            </div>

            <!-- 操作按钮 -->
            <div class="order-actions">
              <!-- 商家出餐按钮 -->
              <button 
                class="action-btn prepare-btn"
                @click="handlePrepareOrder(order.id)"
                :disabled="isProcessing || processingOrderId === order.id"
                v-if="userDetail.identity === 1 && order.status === 2"
              >
                <i class="fa fa-cutlery"></i> 
                <span v-if="processingOrderId === order.id">处理中...</span>
                <span v-else>确认出餐</span>
              </button>

               <!-- 骑手接单/完成配送按钮 -->
              <button 
                class="action-btn accept-btn"
                @click="handleRiderOrder(order.id, order.status)"
                :disabled="isProcessing || processingOrderId === order.id"
                v-if="userDetail.identity === 2 && [3, 4].includes(order.status)"
              >
                <i class="fa fa-bicycle"></i> 
                <span v-if="processingOrderId === order.id">处理中...</span>
                <span v-else-if="order.status === 3">接单配送</span>
                <span v-else>完成配送</span>
              </button>

              <!-- 查看详情按钮 -->
              <button 
                class="action-btn view-btn"
                @click="handleViewDetail(order.id)"
              >
                <i class="fa fa-eye"></i> 查看详情
              </button>
            </div>
          </div>
        </div>

        <!-- 分页控件 -->
        <div 
          class="pagination" 
          v-if="!isLoading && !errorMessage && totalItems > 0"
        >
          <button 
            class="page-btn" 
            @click="changePage(currentPage - 1)"
            :disabled="currentPage === 1 || isLoading"
          >
            上一页
          </button>
          <span class="page-info">
            第 {{ currentPage }} 页 / 共 {{ totalPages }} 页
          </span>
          <button 
            class="page-btn" 
            @click="changePage(currentPage + 1)"
            :disabled="currentPage === totalPages || isLoading"
          >
            下一页
          </button>
          
          <div class="page-size-selector">
            <span>每页显示：</span>
            <select 
              v-model="pageSize" 
              @change="handlePageSizeChange"
              :disabled="isLoading"
            >
              <option value="5">5条</option>
              <option value="6">6条</option>
              <option value="10">10条</option>
              <option value="20">20条</option>
            </select>
          </div>
        </div>
      </section>
    </div>

    <!-- 底部操作栏 -->
    <div class="bottom-action-bar">
      <button 
        class="tab-btn"
        :class="{ active: activeTab === 'orderManage' }"
        @click="activeTab = 'orderManage'"
      >
        <i class="fa fa-tasks"></i> 订单处理
      </button>
      <button 
        class="tab-btn"
        :class="{ active: activeTab === 'historyRecord' }"
        @click="activeTab = 'historyRecord'"
      >
        <i class="fa fa-history"></i> 历史记录
      </button>
    </div>
  </div>
</template>

<script setup>
import { ref, reactive, onMounted, computed, watch, toRefs } from 'vue';
import { useRouter } from 'vue-router';
import axios from 'axios';

// 路由实例
const router = useRouter();

// 状态管理
const state = reactive({
  // 加载与处理状态
  isLoading: true,
  isProcessing: false,
  processingOrderId: null,
  errorMessage: '',
  errorScene: '', // identity_incomplete/no_store/api_error
  
  // 页面状态
  activeTab: 'orderManage', // orderManage/historyRecord
  currentOrders: [], // 当前显示的订单（根据tab切换）
  pendingOrders: [], // 待处理订单
  historyOrders: [], // 历史订单（已完成）
  totalItems: 0, // 当前tab的总记录数
  currentPage: 1, // 当前页码
  pageSize: 6, // 每页条数
  
  // 用户信息
  userDetail: {
    identity: null, // 1:商家, 2:骑手, 3:用户
    user: null
  },
  
  // 配置映射
  identityMap: {
    '1': '商家',
    '2': '骑手',
    '3': '用户'
  },
  rolePageMap: {
    '1': 'StoreManage',
    '2': 'Runner',
    '3': 'Consumer'
  },
  rolePageNameMap: {
    '1': '店铺管理',
    '2': '骑手接单',
    '3': '美食天地'
  },
  roleIconMap: {
    '1': 'fa-shopping-bag',
    '2': 'fa-bicycle',
    '3': 'fa-cutlery'
  },
  orderStatusMap: {
    '1': '待支付',
    '2': '待接单',
    '3': '待派送',
    '4': '派送中',
    '5': '待确认',
    '6': '已完成',
    '7': '已取消'
  },
  statusClassMap: {
    '1': 'status-pending-pay',
    '2': 'status-pending-accept',
    '3': 'status-pending-deliver',
    '4': 'status-delivering',
    '5': 'status-completed',
    '6': 'status-completed',
    '7': 'status-canceled'
  }
});

const {
  isLoading, isProcessing, processingOrderId, errorMessage, errorScene,
  activeTab, currentOrders, pendingOrders, historyOrders, totalItems, 
  currentPage, pageSize, userDetail, identityMap,
  rolePageMap, rolePageNameMap, roleIconMap,
  orderStatusMap, statusClassMap
} = toRefs(state);

// 计算属性
const rolePageName = computed(() => {
  return userDetail.value.identity 
    ? rolePageNameMap.value[userDetail.value.identity] 
    : '';
});

const roleIcon = computed(() => {
  return userDetail.value.identity 
    ? `fa ${roleIconMap.value[userDetail.value.identity]}` 
    : 'fa-arrow-right';
});

// 计算总页数
const totalPages = computed(() => {
  return Math.ceil(totalItems.value / pageSize.value) || 1;
});

// 初始化
onMounted(() => {
  fetchUserIdentity();
});

// 监听Tab切换
watch(activeTab, (newTab) => {
  if (userDetail.value.identity) {
    // 切换到不同tab时重置页码
    currentPage.value = 1;
    fetchData();
  }
});

// 监听页码和页大小变化
watch([currentPage, pageSize], () => {
  if (userDetail.value.identity) {
    fetchData();
  }
});

/**
 * 获取用户身份信息
 */
const fetchUserIdentity = async () => {
  try {
    const response = await axios.put('/user/user/info/');
    userDetail.value = response.data;
    fetchData();
  } catch (err) {
    isLoading.value = false;
    errorScene.value = 'identity_incomplete';
    errorMessage.value = '请先到首页完善个人身份信息';
    console.error('获取用户身份失败:', err);
  }
};

/**
 * 根据当前标签页获取对应数据
 */
const fetchData = async () => {
  if (activeTab.value === 'orderManage') {
    await fetchPendingOrders();
  } else {
    await fetchHistoryOrders();
  }
};

/**
 * 获取待处理订单列表（带分页）
 */
const fetchPendingOrders = async () => {
  try {
    isLoading.value = true;
    errorMessage.value = '';
    
    // 计算偏移量：(当前页-1) * 每页条数
    const offset = (currentPage.value - 1) * pageSize.value;
    const response = await axios.get(`/order/order/?limit=${pageSize.value}&offset=${offset}`);
    
    // 过滤掉已完成状态(6)的订单
    const filteredOrders = response.data.results.filter(order => order.status !== 6) || [];
    
    pendingOrders.value = filteredOrders;
    currentOrders.value = pendingOrders.value;
    totalItems.value = response.data.count - (response.data.results || []).filter(o => o.status === 6).length;
    
    // 处理商家无店铺场景
    if (userDetail.value.identity === 1 && totalItems.value === 0) {
      errorScene.value = 'no_store';
      errorMessage.value = '当前还没有订单';
    }
  } catch (err) {
    errorScene.value = 'api_error';
    errorMessage.value = err.response?.data?.message || '获取订单失败，请重试';
    console.error('获取待处理订单错误:', err);
  } finally {
    isLoading.value = false;
  }
};

/**
 * 获取历史订单列表（已完成状态6，带分页）
 */
const fetchHistoryOrders = async () => {
  try {
    isLoading.value = true;
    errorMessage.value = '';
    
    // 计算偏移量：(当前页-1) * 每页条数
    const offset = (currentPage.value - 1) * pageSize.value;
    const response = await axios.get(`/order/order/history/?limit=${pageSize.value}&offset=${offset}`);
    
    historyOrders.value = response.data.results || [];
    currentOrders.value = historyOrders.value;
    totalItems.value = response.data.count || 0;
  } catch (err) {
    errorScene.value = 'api_error';
    errorMessage.value = err.response?.data?.message || '获取历史订单失败，请重试';
    console.error('获取历史订单错误:', err);
  } finally {
    isLoading.value = false;
  }
};

/**
 * 切换页码
 */
const changePage = (page) => {
  // 验证页码有效性
  if (page < 1 || page > totalPages.value) return;
  currentPage.value = page;
};

/**
 * 改变每页显示条数
 */
const handlePageSizeChange = () => {
  // 改变页大小时重置到第一页
  currentPage.value = 1;
};

/**
 * 商家确认出餐
 */
const handlePrepareOrder = async (orderId) => {
  if (confirm('确定要确认出餐吗？订单状态将改为“待派送”')) {
    try {
      isProcessing.value = true;
      processingOrderId.value = orderId;
      
      // 调用商家出餐接口
      await axios.put(`/order/order/${orderId}/shop/order/`);
      
      // 重新获取当前页数据
      fetchData();
      
      alert('出餐确认成功！订单已转为待派送状态');
    } catch (err) {
      alert(err.response?.data?.message || '出餐确认失败，请重试');
      console.error('商家出餐接口错误:', err);
    } finally {
      isProcessing.value = false;
      processingOrderId.value = null;
    }
  }
};

/**
 * 骑手接单/完成配送
 */
const handleRiderOrder = async (orderId, currentStatus) => {
  const actionText = currentStatus === 3 ? '接单配送' : '完成配送';
  if (confirm(`确定要${actionText}吗？`)) {
    try {
      isProcessing.value = true;
      processingOrderId.value = orderId;
      
      // 调用骑手操作接口
      await axios.put(`/order/order/${orderId}/rider/order/`);
      
      // 重新获取当前页数据
      fetchData();
      
      alert(`${actionText}成功！`);
    } catch (err) {
      alert(err.response?.data?.detail || `${actionText}失败，请重试`);
      console.error('骑手操作接口错误:', err);
    } finally {
      isProcessing.value = false;
      processingOrderId.value = null;
    }
  }
};

/**
 * 查看订单详情
 */
const handleViewDetail = (orderId) => {
  router.push(`/order/${orderId}`);
};

/**
 * 工具函数：格式化时间
 */
const formatTime = (timeStr) => {
  if (!timeStr) return '未知时间';
  const date = new Date(timeStr);
  return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, '0')}-${String(date.getDate()).padStart(2, '0')} ${String(date.getHours()).padStart(2, '0')}:${String(date.getMinutes()).padStart(2, '0')}`;
};

/**
 * 工具函数：格式化价格
 */
const formatPrice = (price) => {
  const numericPrice = Number(price);
  return isNaN(numericPrice) ? '0.00' : numericPrice.toFixed(2);
};

/**
 * 工具函数：获取订单状态文本
 */
const getStatusText = (status) => {
  return orderStatusMap.value[status] || `未知状态(${status})`;
};

/**
 * 工具函数：获取订单状态样式
 */
const getStatusClass = (status) => {
  return statusClassMap.value[status] || 'status-unknown';
};

/**
 * 页面跳转：首页
 */
const goToHome = () => {
  router.push('/home');
};

/**
 * 页面跳转：角色对应功能页
 */
const goToRolePage = () => {
  if (userDetail.value.identity && rolePageMap.value[userDetail.value.identity]) {
    const pageName = rolePageMap.value[userDetail.value.identity];
    router.push(`/${pageName.toLowerCase()}`);
  }
};

/**
 * 页面跳转：首页-个人信息
 */
const goToHomeProfile = () => {
  router.push('/home');
};

/**
 * 退出登录
 */
const handleLogout = () => {
  if (confirm('确定要退出登录吗？')) {
    localStorage.removeItem('token');
    router.push('/login');
  }
};
</script>

<style scoped>
/* 主容器样式 */
.order-container {
  min-height: 100vh;
  background-color: #fff;
  color: #333;
  display: flex;
  flex-direction: column;
}

/* 顶部导航栏 */
.top-nav {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 30px;
  background-color: #ff7a5a;
  color: white;
  box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.logo {
  font-size: 20px;
  font-weight: bold;
}

.logout-btn {
  background-color: white;
  color: #333;
  border: none;
  padding: 8px 15px;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: all 0.3s;
}

.logout-btn:hover {
  background-color: #f8f9fa;
  transform: translateY(-2px);
}

/* 主内容区 */
.main-content {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* 左侧导航区 */
.sidebar {
  width: 200px;
  background-color: #fff5f5;
  padding: 20px 0;
  border-right: 1px solid #ffe0e0;
  display: flex;
  flex-direction: column;
  gap: 5px;
  height: calc(100vh - 65px);
  box-sizing: border-box;
}

.nav-btn {
  width: 100%;
  padding: 15px 20px;
  background: none;
  border: none;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 16px;
  color: #333;
  cursor: pointer;
  transition: all 0.3s;
}

.nav-btn:hover {
  background-color: #ffe8e8;
}

.nav-btn.active {
  background-color: #ffd166;
  color: #333;
  font-weight: bold;
}

.role-entry-btn {
  width: 100%;
  padding: 15px 20px;
  background-color: #ff7a5a;
  color: white;
  border: none;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s;
  margin-top: 10px;
}

.role-entry-btn:hover {
  background-color: #e66a4c;
}

/* 中间工作区域 */
.work-area {
  flex: 1;
  padding: 30px;
  overflow-y: auto;
  background-color: #f9f9f9;
  height: calc(100vh - 65px);
  box-sizing: border-box;
  position: relative;
  padding-bottom: 100px; /* 为底部按钮留出空间 */
}

.page-title {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 25px;
}

.page-title h2 {
  color: #333;
  margin: 0;
  font-size: 22px;
}

.identity-tag {
  background-color: #ffd166;
  color: #333;
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 500;
}

/* 加载状态 */
.loading-state {
  text-align: center;
  padding: 80px 0;
  color: #666;
}

.loading-state i {
  font-size: 40px;
  margin-bottom: 15px;
  color: #ff7a5a;
  animation: spin 1.5s linear infinite;
}

/* 错误状态 */
.error-state {
  background-color: #ffebee;
  border-radius: 8px;
  padding: 30px;
  text-align: center;
  color: #b71c1c;
  margin-bottom: 20px;
}

.error-state i {
  font-size: 40px;
  margin-bottom: 15px;
}

.error-state p {
  margin: 0 0 20px 0;
  font-size: 16px;
}

.reload-btn, .go-profile-btn {
  background-color: #ff7a5a;
  color: white;
  border: none;
  padding: 8px 20px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.3s;
}

.reload-btn:hover, .go-profile-btn:hover {
  background-color: #e66a4c;
}

/* 空状态 */
.empty-state {
  text-align: center;
  padding: 80px 0;
  color: #666;
}

.empty-state i {
  font-size: 60px;
  margin-bottom: 20px;
  color: #ddd;
}

.empty-state p {
  margin: 0 0 10px 0;
  font-size: 18px;
}

.empty-state .tip {
  font-size: 14px;
  color: #999;
}

/* 订单列表 */
.order-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
  gap: 20px;
  margin-top: 20px;
  margin-bottom: 40px; /* 为分页留出空间 */
}

.order-card {
  background-color: white;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.05);
  overflow: hidden;
  transition: transform 0.3s;
}

.order-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}

.order-header {
  padding: 15px 20px;
  border-bottom: 1px solid #f5f5f5;
}

.order-basic {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.order-number {
  margin: 0;
  font-size: 16px;
  color: #333;
}

.order-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
}

.order-time {
  color: #666;
  display: flex;
  align-items: center;
  gap: 5px;
}

.order-status {
  padding: 3px 10px;
  border-radius: 12px;
  font-weight: 500;
  font-size: 13px;
}

/* 订单状态样式 */
.status-pending-pay {
  background-color: #e3f2fd;
  color: #1976d2;
}

.status-pending-accept {
  background-color: #fff8e1;
  color: #f57c00;
}

.status-pending-deliver {
  background-color: #e8f5e9;
  color: #388e3c;
}

.status-delivering {
  background-color: #e0f7fa;
  color: #00acc1;
}

.status-completed {
  background-color: #f1f8e9;
  color: #558b2f;
}

.status-canceled {
  background-color: #ffebee;
  color: #c62828;
}

/* 订单详情 */
.order-detail {
  padding: 15px 20px;
}

.detail-title {
  margin: 0 0 10px 0;
  font-size: 15px;
  color: #555;
  display: flex;
  align-items: center;
  gap: 5px;
}

.detail-title i {
  color: #ff7a5a;
}

.recipient-info {
  margin-bottom: 15px;
  padding-bottom: 15px;
  border-bottom: 1px dashed #eee;
}

.recipient-info p {
  margin: 8px 0;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.recipient-info i {
  color: #999;
  width: 16px;
  text-align: center;
}

.commodity-list {
  margin-bottom: 15px;
  padding-bottom: 15px;
  border-bottom: 1px dashed #eee;
}

.commodity-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  font-size: 14px;
}

.commodity-name {
  flex: 1;
  color: #333;
}

.commodity-count {
  color: #666;
  margin: 0 10px;
}

.commodity-price {
  color: #ff7a5a;
  font-weight: 500;
}

.order-amount {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  font-size: 16px;
  margin-top: 10px;
}

.amount-label {
  color: #666;
  margin-right: 10px;
}

.amount-value {
  color: #e53935;
  font-weight: bold;
}

/* 订单操作按钮 */
.order-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 15px 20px;
  background-color: #f9f9f9;
  border-top: 1px solid #f5f5f5;
}

.action-btn {
  padding: 6px 15px;
  border-radius: 4px;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 14px;
  transition: all 0.3s;
}

.prepare-btn {
  background-color: #4caf50;
  color: white;
}

.prepare-btn:hover {
  background-color: #388e3c;
}

.accept-btn {
  background-color: #2196f3;
  color: white;
}

.accept-btn:disabled {
  background-color: #90caf9;
  cursor: not-allowed;
}

.cancel-btn {
  background-color: #f44336;
  color: white;
}

.cancel-btn:disabled {
  background-color: #ef9a9a;
  cursor: not-allowed;
}

.view-btn {
  background-color: #ff9800;
  color: white;
}

.view-btn:hover {
  background-color: #f57c00;
}

/* 分页样式 */
.pagination {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 15px;
  margin-top: 30px;
  padding: 15px;
  background-color: white;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}

.page-btn {
  padding: 6px 15px;
  background-color: #ff7a5a;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.3s;
}

.page-btn:disabled {
  background-color: #ffb39e;
  cursor: not-allowed;
}

.page-btn:hover:not(:disabled) {
  background-color: #e66a4c;
}

.page-info {
  color: #666;
  font-size: 14px;
}

.page-size-selector {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #666;
  font-size: 14px;
}

.page-size-selector select {
  padding: 4px 8px;
  border: 1px solid #ddd;
  border-radius: 4px;
  cursor: pointer;
}

/* 历史记录占位 */
.history-placeholder {
  text-align: center;
  padding: 100px 0;
  color: #666;
}

.history-placeholder i {
  font-size: 60px;
  margin-bottom: 20px;
  color: #ddd;
}

.history-placeholder p {
  margin: 0 0 10px 0;
  font-size: 18px;
}

.history-placeholder .tip {
  font-size: 14px;
  color: #999;
}

/* 底部操作栏 */
.bottom-action-bar {
  display: flex;
  position: fixed;
  bottom: 0;
  right: 0;
  left: 200px;
  height: 60px;
  background-color: white;
  box-shadow: 0 -2px 10px rgba(0,0,0,0.05);
  z-index: 10;
}

.tab-btn {
  flex: 1;
  background: none;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 16px;
  cursor: pointer;
  transition: all 0.3s;
  color: #666;
}

.tab-btn.active {
  background-color: #ff7a5a;
  color: white;
}

.tab-btn:hover:not(.active) {
  background-color: #f5f5f5;
  color: #333;
}

/* 动画 */
@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* 响应式调整 */
@media (max-width: 768px) {
  .sidebar {
    width: 100%;
    height: auto;
    flex-direction: row;
    overflow-x: auto;
    border-right: none;
    border-bottom: 1px solid #ffe0e0;
  }
  
  .bottom-action-bar {
    left: 0;
  }
  
  .order-list {
    grid-template-columns: 1fr;
  }
  
  .pagination {
    flex-wrap: wrap;
  }
}
</style>